/*
** check_para_type.c for check in /home/yang_j/rendu/CORE_war
** 
** Made by yang jie
** Login   <yang_j@epitech.net>
** 
** Started on  Mon Dec  9 11:43:23 2013 yang jie
** Last update Mon Dec  9 17:23:21 2013 yang jie
*/

int     expod(int a)
{
  int   exit;

  exit = 1;
  while (a > 0)
    {
      exit = exit * 10;
      a = a - 1;
    }
  return (exit);
}

int      my_get_nb(char *str)
{
  int   len;
  int   j;
  int   res;

  res = 0;
  len = my_strlen(str);
  j = len - 1;
  while (len > 0)
    {
      len = len -1;
      res = res + (str[len] - 48) * expod(j - len);
    }
  return (res);
}

int      my_new_get_nb(char *str)
{
  int   len;
  int   j;
  int   res;

  res = 0;
  len = my_strlen(str);
  if (len == 1)
    return (0);
  j = len - 1;
  while (len > 1)
    {
      len = len -1;
      res = res + (str[len] - 48) * expod(j - len);
    }
  return (res);
}

int	regeister_type(char *str)
{
  int	res;

  res = my_new_get_nb(str);
  my_putnbr(res);
  my_putchar('\n');
  if (res > 0 && res < 17)
    return (1);
  else
    my_putstr("Usage : regeister:1 - 16");
}

int	check_type(char *str)
{
  int	res;

  if (str[0] == '%')
    {
      res = my_new_get_nb(str);
      my_putnbr(res);
      my_putchar('\n');
      if (res >= 0 && res <= 2147483647)
	return (2);
      else
	my_putstr("usage : Dir: 0 - 2147483647");
    }
  else if (str[0] == 'r')
    return (regeister_type(str));
  else if (str[0] >= 48 && str[0] <= 48 + 9)
    {
      res = my_get_nb(str);
      my_putnbr(res);
      my_putchar('\n');
      if (res >= 0 && res <= 2147483647)
	return (4);
      else
	my_putstr("usage : indir: 0 - 2147483647");
    }
  else
    my_putstr("unvalied parameter type.");
}

